package com.zzq.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzq.Model.Article;
import com.zzq.Model.User;
import com.zzq.mapper.UserArticleMapper;
import com.zzq.utils.IResult;
import com.zzq.utils.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("用户文章接口")
@Controller
@RequestMapping("/userArticle")
public class UserArticleController {
    @Autowired
    UserArticleMapper userArticleMapper;

    @ApiOperation("通过用户的文章数排序用户(取前十个)")
    @GetMapping("getUsersByArticleCount.do")
    @ResponseBody
    public IResult<User> getUsersByArticleCount() {
        try {
            List<Map<String, Object>> usersByArticleCount = userArticleMapper.getUsersByArticleCount();
            return IResult.success(usersByArticleCount);
        } catch (Exception e) {
            Log.LogWarn(e.toString());
            return IResult.error(e.toString());
        }
    }

    @ApiOperation("通过用户的文章浏览数排序用户(取前十个)")
    @GetMapping("getUsersByArticleTotalView.do")
    @ResponseBody
    public IResult<Map<String, Object>> getUsersByArticleTotalView() {
        try {
            List<Map<String, Object>> usersByArticleTotalView = userArticleMapper.getUsersByArticleTotalView();
            return IResult.success(usersByArticleTotalView);
        } catch (Exception e) {
            Log.LogWarn(e.toString());
            return IResult.error(e.toString());
        }
    }
}
